﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data;
using System.Web.SessionState;

namespace wxx.ashx
{
    /// <summary>
    /// 生成代码时间： ljxtime
    /// 文件说明：t_librarybookinfo
    /// 开发者：
    /// 最后编辑时间：
    /// 编辑说明：
    /// </summary>
    public class librarybookinfo : baseashxClass
    {
        
        public override void ProcessRequest(HttpContext context)
        {
            wxx.BLL.t_librarybookinfo bll = new wxx.BLL.t_librarybookinfo(context); 

            base.ProcessRequest(context);
            context.Response.ContentType = "text/plain";

            mycommonClass mycommonClassobj = new mycommonClass();
            context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            if (context.Request.QueryString["type"] == "edit")//获取编辑信息
            {
                if (context.Request.QueryString["Id"] != null)
                {
                    string strret = bll.Geteditdata(context.Request.QueryString["Id"].ToString());//aa1
                    context.Response.Write(strret);
                }
            }
            else if (context.Request.QueryString["type"] == "del")//删除信息
            {
                if (context.Request.QueryString["Id"] == null)
                    return;
                string Id = context.Request.QueryString["Id"].ToString();
                wxx.Model.t_librarybookinfo lbimodel = new wxx.Model.t_librarybookinfo();
                lbimodel = bll.GetModel(int.Parse(Id));
                String State = lbimodel.BookState;
                if (State == "未借出")//只有未借出的书才可以被删掉
                {
                    String ISBN = lbimodel.ISBN;
                    //书本可借数量减少
                    wxx.BLL.t_bookinfo bibll = new wxx.BLL.t_bookinfo();
                    wxx.Model.t_bookinfo bimodel = new wxx.Model.t_bookinfo();
                    DataSet bids = bibll.GetList("ISBN='" + ISBN + "'");
                    String idbi = bids.Tables[0].Rows[0][0].ToString();
                    bimodel = bibll.GetModel(int.Parse(idbi));
                    String oldnum = bimodel.Beizhu;
                    bimodel.Beizhu = (int.Parse(oldnum) - 1).ToString();
                    bibll.Update1(bimodel);
                    bll.Delete(int.Parse(Id));
                    context.Response.Write("true");
                }
                else
                {
                    context.Response.Write("false");
                    
                }

            }
            else if (context.Request.QueryString["type"] == "combox")//保存修改或添加 信息 aa2
            {
                        if (context.Request.QueryString["comboxname"] == "ISBN")
                        {
                            wxx.BLL.t_bookinfo bllzd = new wxx.BLL.t_bookinfo();
                            string strret = bllzd.GetListByColumn_tojson("Id,ISBN,BookName,ISBN","1=1","");
                            context.Response.Write(strret);
                        }


            }
             
            else if (context.Request.QueryString["type"] == "save")//保存修改或添加 
            {
                    string ISBN = context.Request.QueryString["ISBN"];
                    string BarCodeId = context.Request.QueryString["BarCodeId"];
                    string BarCodeId2 = DateTime.Now.ToFileTime().ToString();
                    string RukuDate = context.Request.QueryString["RukuDate"];
                    string RukuDate2 = DateTime.Now.ToString();
                    string BookState = context.Request.QueryString["BookState"];
                    string Operation = context.Session["username"].ToString();

                
                if (context.Request.QueryString["Id"] != null && context.Request.QueryString["Id"] != "")
                {
                    bll.Update(context.Request.QueryString["Id"].ToString(),ISBN,BarCodeId,RukuDate,BookState,Operation);
                }
                else
                {
                    bll.Add(ISBN,BarCodeId2,RukuDate2,BookState,Operation);
                    //书本的可借数量增加
                    wxx.BLL.t_bookinfo bibll = new wxx.BLL.t_bookinfo();
                    wxx.Model.t_bookinfo bimodel = new wxx.Model.t_bookinfo();
                    DataSet bids = bibll.GetList("ISBN='" + ISBN + "'");
                    String idbi = bids.Tables[0].Rows[0][0].ToString();
                    bimodel = bibll.GetModel(int.Parse(idbi));
                    String oldnum = bimodel.Beizhu;
                    bimodel.Beizhu =(int.Parse(oldnum)+1).ToString();
                    bibll.Update1(bimodel);
                }

                context.Response.Write("true");
            }
            else if (Convert.ToString(context.Request.Form["action"]) == "query1")
            {
                string StrCom = "";
                string sArray = "";
                string urlstr = context.Request.UrlReferrer.Query;
                if (urlstr != null && urlstr != "")
                {
                    StrCom = urlstr.Substring(urlstr.IndexOf("="));//得到="传进来的参数"
                    sArray = StrCom.Split('=')[1].ToString();
                }

                //string strret = bll.GetListByPageColumns_tojson("id,产品名称,产品数量,产品规格,备注", "1=1", "产品数量"); 加权限, 1=1 改为:部门编号 like '1010%'
                string strret = bll.GetListByPageColumns_tojson("Id,ISBN,BarCodeId,RukuDate,BookState,Operation","ISBN='"+sArray+"'", "Id");
                context.Response.Write(strret);
                return;
            }
            else if (Convert.ToString(context.Request.Form["action"]) == "query")
            {
                //string strret = bll.GetListByPageColumns_tojson("id,产品名称,产品数量,产品规格,备注", "1=1", "产品数量"); 加权限, 1=1 改为:部门编号 like '1010%'
                string strret = bll.GetListByPageColumns_tojson("Id,ISBN,BarCodeId,RukuDate,BookState,Operation", "BookState=" + "'未借出'", "Id");
                context.Response.Write(strret);
                return;
            }
            else if (Convert.ToString(context.Request.Form["action"]) == "query2")
            {
                //string strret = bll.GetListByPageColumns_tojson("id,产品名称,产品数量,产品规格,备注", "1=1", "产品数量"); 加权限, 1=1 改为:部门编号 like '1010%'
                string strret = bll.GetListByPageColumns_tojson("Id,ISBN,BarCodeId,RukuDate,BookState,Operation",pagestrif, "Id");
                context.Response.Write(strret);
                return;
            }
            else
            {
                
            }
        }         
    }
}